// main layer
var g_emiEnemy=null;
var g_emiEnemyDown=false;
var emiEnemy = cc.Node.extend({
    _jsonObject : null,
    _enemyGroup : 0,
    _allEmitter : 0,
    _curEmitter : 0,
    ctor:function ( jsonfilename ) {
        this._super();
        // add map
        g_emiEnemy=this;
        this._jsonObject=CreateJsonWithFile(jsonfilename);
        return true;
    },
    onEnter:function () {
        this._super();
    },
    emission : function(){
        var jsonObject=this._jsonObject;
        if(jsonObject){
            // emitter all enemy then stop
            if( this._enemyGroup<jsonObject.emitter.length ){
                var emit = jsonObject.emitter[this._enemyGroup];
                this._curEmitter = 0;
                this._allEmitter = emit.num-1;
                this.schedule( this.interval,emit.st,this._allEmitter,emit.dl);
            }
        }else{
            cc.log(" enemy json invalid");
        }
    },
    interval : function(dt){
        var jsonObject=this._jsonObject;
        var emit = jsonObject.emitter[this._enemyGroup];
        var name = "res/"+emit.res;
        var enemy = Enemy.create(name,jsonObject.direct,emit.hp,emit.sp,emit.gold);
        enemy.setPosition( cc.p(jsonObject.x,jsonObject.y ) );
        enemy.setAnchorPoint( cc.p(0.5,0.0) );
        this.addChild(enemy,15);
        if( ++this._curEmitter > this._allEmitter ){
            if(++this._enemyGroup>=jsonObject.emitter.length){
                this._enemyGroup = 0;
                g_emiEnemyDown = true;
                cc.log("current enemy group emitter down");
            }else{
                cc.log("increment current enemy group");
            }
        }
    }
});

